#include <bits/stdc++.h>

using namespace std;

class Solution
{
public:
    bool lemonadeChange(vector<int> &bills)
    {
        int nums[21] = {0};
        int length = bills.size();
        for (int i = 0; i < length; i++)
        {
            nums[bills[i]]++;
            if (bills[i] == 10)
            {
                nums[5]--;
            }
            if (bills[i] == 20)
            {
                if (nums[10] > 0)
                {
                    nums[10]--;
                    nums[5]--;
                }
                else
                {
                    nums[5] -= 3;
                }
            }
            if (nums[5] < 0)
            {
                return false;
            }
        }
        return true;
    }
};

int main()
{
    vector<int> bills{5, 5, 10, 10, 20};
    Solution sol;
    cout << sol.lemonadeChange(bills) << endl;
    return 0;
}